<template>
  <div class="app-container">
    <!-- 顶部导航栏 -->
    <div class="nav-bar">
      <div class="logo-container">
        <img class="logo" :src="LOGO" alt="">
        <p class="logo-text">麦好货应用中心</p>
      </div>
      <ul class="nav-links">
        <li><a href="#" class="nav-link">文档中心</a></li>
        <a href="#" class="nav-link" @click.prevent="navigateToConsole">控制台</a>
        <!-- 根据登录状态显示不同的按钮 -->
        <li v-if="!token">
          <el-button type="info" @click="login">登录</el-button>
        </li>
        <el-dropdown v-if="token" class="avatar-container right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
            <span>{{ user.user.username }}</span>
            <!-- <i class="el-icon-caret-bottom" /> -->
            <img style="margin-left:10px" :src="user.avatarName ? baseApi + '/avatar/' + user.avatarName : LOGO" class="user-avatar">
          </div>
          <el-dropdown-menu slot="dropdown">
            <router-link to="/user/center">
              <el-dropdown-item>
                个人中心
              </el-dropdown-item>
            </router-link>
            <span style="display:block;" @click="doLogout">
              <el-dropdown-item divided>
                退出登录
              </el-dropdown-item>
            </span>
          </el-dropdown-menu>
        </el-dropdown>
      </ul>
    </div>
    <!-- 主体内容 -->
    <main class="main-content">
      <div class="hero-section">
        <div class="main">
          <h1 class="hero-title">开放生态，助力商家</h1>
          <h2 class="hero-subtitle">赋能内容电商生态，服务商家与开发</h2>
          <el-button size="medium" type="primary" class="start-btn" @click="navigateToConsole">立即入驻</el-button>
        </div>
        <div class="image" style="flex-grow: 1; order: 2; margin: 0; min-height: 100%">
          <div class="image-container">
            <div class="image-bg" />
            <img class="VPImage image-src" :src="LOGO2" alt="Kitty">
          </div>
        </div>
      </div>
      <!-- 功能介绍模块 -->
      <div class="feature-section">
        <div class="feature-item">
          <i
            class="feature-icon icon-blue el-icon-s-help"
          />
          <h3 class="feature-title">最新技术栈</h3>
          <p class="feature-description">全面满足电商生态 商家所需</p>
        </div>
        <div class="feature-item">
          <i class="feature-icon  icon-cyan el-icon-s-custom" />
          <h3 class="feature-title">自研商家</h3>
          <p class="feature-description">为具备自主研发能力的商家提供数据能力支持</p>
        </div>
        <div class="feature-item">
          <i class="feature-icon icon-orange el-icon-user-solid" />
          <h3 class="feature-title">软件服务商</h3>
          <p class="feature-description">基于开放能力开发订单管理、商品搬家等软件上架服务市场服务抖店商家</p>
        </div>
        <div class="feature-item">
          <i class="feature-icon icon-purple el-icon-setting" />
          <h3 class="feature-title">电商ERP</h3>
          <p class="feature-description">为商家提供供应链管理、商品管理、订单管理、库存管理、物流管理、逆向处理等服务</p>
        </div>
        <div class="feature-item">
          <i class="feature-icon icon-orange el-icon-s-order" />
          <h3 class="feature-title">订单管理</h3>
          <p class="feature-description">为商家提供订单处理、发货履约、售后处理、多店铺运营等店铺基本订单管理服务</p>
        </div>
        <div class="feature-item">
          <i class="feature-icon icon-green el-icon-s-goods" />
          <h3 class="feature-title">商品管理 </h3>
          <p class="feature-description">为抖音平台商家提供产品一键搬家、上架，内容及设计优化，产品数据分析及关键词优化等服务</p>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      avatarSrc: require('@/assets/images/logo.png'),
      LOGO: require('@/assets/images/logo1.png'),
      LOGO2: require('@/assets/images/logo2.png')
    }
  },
  computed: {
    ...mapState({
      user: state => state.user,
      token: state => state.user.token
    })
  },
  methods: {
    doLogout() {
      this.$confirm('您确定要退出登录吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.reload()
        })
      }).catch(() => {})
    },
    login() {
      const currentPath = this.$route.fullPath
      this.$router.push({ path: '/login', query: { redirect: currentPath }})
    },
    navigateToConsole() {
      if (this.token) {
        this.$router.push('/dashboard')
      } else {
        this.$router.push('/login')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .app-container {
    padding: 0;
  }
  .nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 120px;
    background-color: #fff;
    height: 72px;
  }
  .logo-container {
    height: 30px;
    display: flex;
    align-items: center;
  }

  .nav-links {
    list-style-type: none;
    display: flex;
    align-items: center;
  }
  .logo {
    height: 24px;
    margin-right: 10px;
  }
  .logo-text {
    font: 16px bold;
  }
  .nav-link {
    margin-right: 20px;
  }
  .login-btn {
    border: 1px solid #ccc;
    padding: 5px 10px;
    border-radius: 5px;
  }
  .profile-btn {
    border: 1px solid #ccc;
    padding: 5px 10px;
    border-radius: 5px;
  }
  .main-content {
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    margin-top: 30px;
    padding: 0 200px;
  }
  .hero-section {
    margin-bottom: 50px;
    display: flex;
    justify-content: space-between;
  }
  .hero-title {
    box-sizing: border-box;
    word-break: break-word;
    line-height: 64px;
    font-size: 56px;
    color: #1e6fff;
    text-align: left;
    font-weight: bold;
  }
  .hero-subtitle {
    font-weight: bold;
    margin-bottom: 30px;
    line-height: 64px;
    font-size: 56px;
    text-align: left;
  }
  .large-logo {
    height: 100px;
    margin-bottom: 30px;
  }
  .start-btn,
  .preview-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    margin-right: 10px;
    cursor: pointer;
  }
  .start-btn {
    background-color: #007bff;
    color: #fff;
  }
  .preview-btn {
    background-color: #f4f4f4;
    color: #333;
  }
  .feature-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }
  .feature-item {
    width: 30%;
    margin-bottom: 30px;
    padding: 20px;
    border-radius: 5px;
    background-color: #f9f9f9;
  }
  .image-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    transform: translate(-32px, -32px);
  }
  .image-bg {
    width: 320px;
    height: 320px;
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
  }
  .VPImage.image-src {
    max-width: 320px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .feature-icon {
    height: 40px;
    margin-bottom: 10px;
    font-size: 40px;
  }
  .icon-blue {
    color: #007bff;
  }
  .icon-green {
    color: rgb(18, 116, 197);
  }
  .icon-red {
    color: rgb(16, 100, 96);
  }
  .icon-purple {
    color: rgb(0, 128, 117);
  }
  .icon-orange {
    color: orange;
  }
  .icon-cyan {
    color: cyan;
  }
  .feature-title {
    line-height: 24px;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
  }
  .feature-description {
    padding-top: 8px;
    line-height: 24px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(60, 60, 60, 0.7);
    margin: 0;
  }
  .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        position: relative;
        font-size: 18px;
        cursor: pointer;
        display: flex;
        align-items: center;
        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
</style>
